package com.hualan.sfzy.controller.consult;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.consult.ConsultChargesMapper;
import com.hualan.sfzy.model.entity.ConsultCharges;
import com.hualan.sfzy.service.impl.consult.ConsultChargesServiceImpl;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/consultCharges")
// 咨询师收费标准控制类

public class ConsultChargesController {
    @Autowired
    private ConsultChargesServiceImpl service;

    @PostMapping
    // 添加咨询师收费标准信息
    public Result add(@RequestBody ConsultCharges entity) {
        return service.add(entity) > 0 ? Result.success() : Result.error();
    }

    @PutMapping
    // 修改咨询师收费标准信息
    public Result edit(@RequestBody ConsultCharges entity) {
        return service.edit(entity) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/{id}")
    // 根据 id 删除咨询师收费标准信息
    public Result remove(@PathVariable("id") Integer id) {
        return service.remove(id) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping
    // 批量删除咨询师收费标准信息
    public Result removeBatch(Integer[] ids) {
        return service.removeBatch(ids) > 0 ? Result.success() : Result.error();
    }

    @GetMapping
    // 查找全部咨询师收费标准信息
    public Result find() {
        return Result.success(service.find());
    }

    @GetMapping("/{id}")
    // 根据 id 查询咨询师收费标准信息
    public Result findById(@PathVariable("id") Integer id) {
        return Result.success(service.findById(id));
    }

    @GetMapping("/page")
    // 分页查询咨询师收费标准信息
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           ConsultCharges consultCharges) {
        return Result.success(service.findPage(pageNum, pageSize, consultCharges));
    }

    // 小程序根据 咨询师id查询收费标准
    @GetMapping("/consultId/{id}")
    public Result findByConsultId(@PathVariable Integer id) {
        return Result.success(service.findByConsultId(id));
    }

}
